using System;
using System.Collections.Generic;
using MSOffice = Microsoft.Office.Core;
using MSOutlook = Microsoft.Office.Interop.Outlook;

namespace Microsoft.Sample.Outlook.Utility
{

	public abstract class ToolbarControl
	{
		private string _id;
		private string _caption;
		private string _toolTip;
		private int? _position;

		List<MSOffice.CommandBarControl> _listControls = new List<MSOffice.CommandBarControl>();

		public string ID
		{
			get { return _id; }
			set { _id = value; }
		}
	
		public string Caption
		{
			get { return _caption; }
			set { _caption = value; }
		}

		public string ToolTip
		{
			get { return _toolTip; }
			set { _toolTip = value; }
		}

		public int? Position
		{
			get { return _position; }
			set { _position = value; }
		}


		public ToolbarControl(string ID)
		{
			_id = ID;
			_caption = ID;
		}

		public ToolbarControl(string ID, string caption)
		{
			_id = ID;
			_caption = caption;
		}

		public ToolbarControl(string ID, string caption, string tooltip)
			: this(ID, caption)
		{
			_toolTip = tooltip;
		}

		protected MSOffice.CommandBarControl FindControl(MSOffice.CommandBar bar)
		{
			foreach (MSOffice.CommandBarControl ctl in bar.Controls)
			{
				if (ctl.Parameter == this.ID)
				{
					return ctl;
				}
			}
			return null;
		}

		protected TControl FindControl<TControl>(MSOffice.CommandBar bar) where TControl : class
		{
			MSOffice.CommandBarControl ctl = FindControl(bar);

			if (ctl != null)
			{
				if (!(ctl is TControl))
				{
					ctl.Delete(false);
					return null;
				}
				else
					return (TControl)ctl;
			}

			return null;

		}


		protected void AddControl(MSOffice.CommandBarControl control)
		{
			_listControls.Add(control);
		}

		protected void RemoveControl(MSOffice.CommandBarControl control)
		{
			_listControls.Remove(control);
		}

		internal abstract void Attach(MSOffice.CommandBar bar, WindowAdapter window);


	}

	//public class ToolbarBarEdit : ToolbarControl
	//{
	//}

	//public class ToolbarComboBox : ToolbarControl
	//{
	//}



}
